feat: Add PHPUnit configuration and unit tests for Hyvä compatibility…#212
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds PHPUnit-based unit testing to MageForge and refines the Hyvä compatibility scanning/reporting logic (broader Knockout/template detection, simplified APIs, and more resilient error handling).
Changes:
- Introduce PHPUnit test infrastructure (dependency, config, CI workflow) and add unit tests for
IncompatibilityDetector. - Expand Hyvä incompatibility detection to include more Knockout patterns and scan
.htmltemplates in addition to.js,.xml, and.phtml. - Simplify compatibility-check APIs/output logic (signature cleanup, improved status display, and
\Throwable-based resilience).
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/Service/Hyva/IncompatibilityDetectorTest.php | Adds unit tests covering JS/XML/PHTML/HTML pattern detection and edge cases. |
| src/Service/Hyva/ModuleScanner.php | Extends scanning to .html files and reuses detector extension parsing; broadens exception catch to \Throwable. |
| src/Service/Hyva/IncompatibilityDetector.php | Expands Knockout/template pattern detection, maps .html into template scanning, and makes extension parsing reusable. |
| src/Service/Hyva/CompatibilityChecker.php | Adjusts summary/detail triggering for warnings, improves Hyvä-aware status display, and simplifies getDetailedIssues() signature. |
| src/Console/Command/Hyva/CompatibilityCheckCommand.php | Updates call sites to the simplified CompatibilityChecker method signatures. |
| phpunit.xml.dist | Adds PHPUnit suite configuration (bootstrap, cache directory, source include). |
| composer.json | Adds phpunit/phpunit and PSR-4 autoload-dev for tests. |
| .phpunit.cache/test-results | Adds a PHPUnit test result cache artifact. |
| .github/workflows/phpunit.yml | Adds a GitHub Actions workflow to run PHPUnit on pull requests. |
Files not reviewed (1)
- .phpunit.cache/test-results: Generated file
Comments suppressed due to low confidence (1)
src/Service/Hyva/IncompatibilityDetector.php:205
getExtensionFromPath()was made public and is now used byModuleScanner, which increasesIncompatibilityDetector's public API surface and couples scanning logic to a detector implementation detail. Prefer keeping extension parsing as a private helper inModuleScanner(or extracting a small shared path utility) soIncompatibilityDetectoronly exposes detection-related behaviour.
/**
* Get file extension without using pathinfo().
*
* @param string $path
* @return string
*/
public function getExtensionFromPath(string $path): string
{
$normalized = str_replace('\\', '/', $path);
$trimmed = rtrim($normalized, '/');
$pos = strrpos($trimmed, '/');
$basename = $pos === false ? $trimmed : substr($trimmed, $pos + 1);
$dot = strrpos($basename, '.');
…for better readability
…d add tests for false positives
Comment on lines
228
to
232
| @@ -234,13 +232,7 @@ private function runScan( | |||
| $excludeVendor = false; | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces PHPUnit test support and refines the Hyvä compatibility checking logic for improved accuracy and maintainability. The main changes include adding test infrastructure, updating detection logic for Knockout.js and HTML templates, and simplifying code by removing unused methods and parameters.
Testing infrastructure:
.github/workflows/phpunit.ymlGitHub Actions workflow to run unit tests on pull requests.phpunit/phpunittocomposer.jsonand configured PSR-4 autoloading for tests.phpunit.xml.distfor test suite configuration.Compatibility detection improvements:
pureComputed,applyBindings,components,bindingHandlers, anddata-bindattribute). [1] [2].htmlfiles in addition to.js,.xml, and.phtml. [1] [2]Codebase simplification and robustness:
CompatibilityChecker,IncompatibilityDetector, andModuleScanner(e.g., output interface, severity helpers, redundant extension methods). [1] [2] [3] [4] [5]\Throwableinstead of just\Exceptionfor better error resilience. [1] [2] [3]Result reporting improvements:
API changes:
getDetailedIssues, removing unnecessary parameters. [1] [2]These changes collectively improve testability, detection accuracy, and code maintainability.… detection